const express = require('express');

const router = express.Router();

// 引入读取文件的中间件: readFileSync 同步读取文件
const { readFileSync } = require('fs');
// 找到绝对路径： resole 拼接路径
const { resolve } = require('path');
router.post('/uploadAnswer', function (reg, res) {
    const { order, myAnswer } = reg.body;
    const questionData = JSON.parse(readFileSync(resolve(__dirname, '../data/question.json'), 'utf-8'));
    const { id, question, items, answer } = questionData[order];
    myResult.push({
        qId: id,
        question,
        myAnswer: items[myAnswer],
        rightAnswer: items[answer],
        isTrue: myAnswer == answer
    });

    res.send({
        errorCode: 0,
        msg: 'OK'
    })
});

module.exports = router;